<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>病案集中归档</title>
</head>
<body>
<div class="easyui-panel" data-options="fit:true,border:0">
	<div id="archivingBar" class="paddingTBL">
	    <div class="paddingB">
	        <label>出院科室&nbsp;</label>
			<input type="text" class="" id="archiving_fcydept" data-options="width:120,height:24"/>
		    <label class="paddingL">出院日期&nbsp;</label>
			<input type="text" class="easyui-datebox" id="archiving_fcydate1" data-options="width:115,height:24"/>
			<label>&nbsp;至&nbsp;</label>
			<input type="text" class="easyui-datebox" id="archiving_fcydate2" data-options="width:115,height:24"/>
	    	<label class="paddingL">出院病区&nbsp;</label>
		    <input type="text" class="" id="archiving_fcybq" data-options="width:120,height:24"/>
		   
	    </div>
		<div class="paddingB">
	    	<label class="labelWid4">姓&nbsp;名&nbsp;</label>
			<input type="text" class="easyui-textbox" id="archiving_fname" data-options="width:120,height:24"/>
	    	<label class="labelWid4 paddingL">病案号&nbsp;</label>
			<input id="archiving_fprn" class="easyui-textbox" data-options="prompt:'条码号/住院号',width:262,height:24" />
			<label class="paddingL">主治医生&nbsp;</label>
			<input type="text" class="" id="archiving_fzydoc" data-options="width:120,height:24"/>
		</div>
		<div>
		    <label class="labelWid4">归档状态</label>
			<select class="easyui-combobox" id="archiving_status" data-options="width:120,height:24">
				<option value="0" selected="selected">全部</option>
	            <option value="1">已归档</option>
	            <option value="2">未归档</option>
		    </select>
		    <label class="paddingL">已出院天数≥</label>
			<input type="text" class="easyui-numberbox" id="archiving_fday" data-options="width:120,height:24"/>
			<label class="">天</label> 
			<span class="paddingL"></span>
			<a href="#" class="easyui-linkbutton" onclick="queryArchiving()">检 索</a>
		</div>
	</div>
 
	<table id="archivingListGrid"></table>
	
	<!-- 预览窗口  -->
	<div id="archivingDialog" class="easyui-dialog"  data-options="closed:true" style="width:100%;height:100%;">
		 <!-- 该页面为公共浏览页，所以当不同的页面调用此页面时需给一个表示，通过此标识开放一定的权限 。1 ：表示归档操作 -->
		<%-- <jsp:include page="../MedicalShootManage/Shoot.jsp" >
			<jsp:param value="1" name="tag"/>
			<jsp:param value="archivingDialog" name="dialog"/>
		</jsp:include> --%>
		<!-- <div  class="easyui-panel" data-options="href:ctx+'/MedicalShootManage/Shoot?tag=1&dialog=archivingDialog'" style="height: 100%;width:100%;"></div> -->	
	</div>
	
</div>  
<!-- 主页引入 -->
<%-- <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery/plug/slides/responsiveslides.min.js"></script>
<script type="text/javascript" src='<%=request.getContextPath()%>/script/jquery/plug/viewer/jquery.js'></script> 
<script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery/plug/viewer/jquery.iviewer.js"></script>
<script type="text/javascript" src='<%=request.getContextPath()%>/script/jquery/plug/viewer/jquery.mousewheel.min.js'></script>
<script type="text/javascript" src='<%=request.getContextPath()%>/script/jquery/plug/zoom/jquery.zoom.js'></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery/plug/media/jquery.media.js" ></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery/plug/media/jquery.metadata.js" ></script>  --%>

<script type="text/javascript">

$(function(){
	//获取出院科室
	$("#archiving_fcydept").combobox({
		url:ctx + "/Archiving/getDeptByFcode",
		valueField:"ftykh",
		textField:"fksname",
		width:120, 
		height:24,
		queryParams :{
			"fcode" : sysFcode
		},
		onLoadSuccess : function() {
			$('#archiving_fcydept').combobox('select', 'TZYQY');
		},
		onSelect : function(record){
			var code = record.ftykh;
			loadCybs(code);
		}
	});
	
	//获取主治医生
	$("#archiving_fzydoc").combobox({
		url:ctx + "/MedicalShootManage/getZzDoc",
		valueField:"fzzdoctbh",
		textField:"fzzdoct",
		width:120, 
		height:24
	});
});

//获取出院病区
function loadCybs(code){
	var ksbh = "";
	if(code != "" && code != null){
		ksbh = code;
	}
	$("#archiving_fcybq").combobox({
		url:ctx + "/Archiving/getFcybs",
		valueField:"fhiskh",
		textField:"fhisksname",
		width:120, 
		height:24,
		queryParams : {
			'ksbh' : ksbh,
			"fcode" : sysFcode
		},
		onLoadSuccess : function(){
			if(sysFbqdm != "" && sysFbqdm != null){
				$("#archiving_fcybq").combobox('select',sysFbqdm);
			}
		}
		
	});
}

//查询数据
function queryArchiving(){
	var date1 = $("#archiving_fcydate1").datebox("getValue");
	var date2 = $("#archiving_fcydate2").datebox("getValue");
	var fcydept = $("#archiving_fcydept").combobox("getValue");
	var fcybq = $("#archiving_fcybq").combobox("getValue");
	var status = $("#archiving_status").combobox("getValue");
	var fprn = $("#archiving_fprn").textbox("getValue");
	var fname = $("#archiving_fname").textbox("getValue");
	var fzzDoc = $("#archiving_fzydoc").combobox("getValue");
	var day = $("#archiving_fday").numberbox("getValue");
	$("#archivingListGrid").datagrid({
		url:ctx + "/Archiving/queryArchiving",
		queryParams:{
			"date1" : date1,
			"date2" : date2,
			"fcydept" : fcydept,
			"fzzDoc" : fzzDoc,
			"fprn" : fprn,
			"fname" : fname,
			"fcybq" : fcybq,
			"status" : status,
			"day" :day
		}
	});
}


//加载数据表格
$("#archivingListGrid").datagrid({
	url:'',
	toolbar:"#archivingBar",
	rownumbers:true,
	fitColumns:false,
	border : false,
	striped : true,
	fit : true,
	singleSelect: true,
	pagination : true,
	pageSize : 20,
	pageList : [ 20, 30,50 ],
	columns:[[
        {field:'operat',title:'操作',width:80,align:'center',
        	formatter:function(value,row,index){
        		if(row.fstatus == null || row.fstatus == "" || row.fstatus == '0'){
        			return "<button class='shootBtn' onclick='archiving("+index+")'>归档</button>";
        		}else{
        			return "<button class='shootBtn' onclick=''>撤销归档</button>";
        		}
        	}
        },  
		{field:'fstatus',title:'状态',width:60,align:'center',
        	formatter : function(value,row,index){
        		if(value == null || value == "" ||  value == "0" ){
        			return "未归档";
        		}else{
        			return "已归档";
        		}
        		return value;
        	}	
		},  
		{field:'days',title:'归档天数',width:80,align:'center' },  
		{field:'page',title:'归档页数',width:80,align:'center'},  
		{field:'fname',title:'姓名',width:80,align:'center' },  
		{field:'fsex',title:'性别',width:50,align:'center' },  
		{field:'ftimes',title:'次数',width:50,align:'center' },  
		{field:'fcydept',title:'出院科室',width:100,align:'center' },  
		{field:'fcybs',title:'出院病区',width:100,align:'center' },  
		{field:'fprn',title:'病案号',width:120,align:'center'},  
		{field:'fzyid',title:'住院ID',width:100,align:'center'},  
		{field:'fbarcode',title:'条码号',width:160,align:'center' },  
		{field:'fcydate',title:'出院日期',width:100,align:'center',
			formatter:function(value){
				return new Date(value).format("yyyy-MM-dd");
			}
		},  
		{field:'fzzdoct',title:'主治医生',width:80,align:'center' },  
		{field:'fzzdoctbh',title:'主治医生编号',width:100,align:'center',hidden:true },  
		{field:'fdate',title:'归档日期',width:100,align:'center',hidden:true },  
		{field:'detail',title:'详情',width:100,align:'center',hidden:true },	//存放没份病历的归档情况  
		{field:'frydate',title:'入院日期',width:100,align:'center',hidden:true,
			formatter:function(value){
				return new Date(value).format("yyyy-MM-dd");
			}	
		} 
	       ]],
	onLoadSuccess:function(data){
		//获取当前页所有住院ID，通过住院ID查询没分病案的归档数量
		var array = data.rows;
		var fzyids = "";
		for (var i = 0; i < array.length; i++) {
			if(i > 0){
				fzyids += "," + array[i].fzyid;
			}else{
				fzyids += array[i].fzyid;
			}
		}
		 $.ajax({
			url : ctx + '/Archiving/getArchivingByFzyid' ,
			dataType : 'json',
			type : 'post',
			data : {
				'fzyids' : fzyids 
			},
			success : function(data){
				//将每份病案归档的记录放入的表格中
				var rows = $('#archivingListGrid').datagrid("getRows");
				var fzyid = "";
				var total = 0;
				var detail = "";
				for (var i = 0; i < data.length; i++) {
					var arr = data[i];
					for (var j = 0; j < arr.length; j++) {
						 fzyid = arr[0].fzyid;
						 total = arr[arr.length-1].total;
						 if(j <= 3){
							 if(j > 0){
								 detail += ","+""+arr[j].fname+"("+arr[j].number+")";
							 }else{
								 detail += ""+arr[j].fname+"("+arr[j].number+")";
							 }
						 }
					}
					for (var k = 0; k < rows.length; k++) {
						//将已归档的记录填充进去
						if(rows[k].fstatus == "1"){
							if(rows[k].fzyid == fzyid){
								$('#archivingListGrid').datagrid('updateRow',{
									index: k,
									row:{
										page : "<div id='details"+k+"' onclick='preview("+k+")'><a href='#' style='cursor:help;'>"+total+"</a></div>",
										detail : detail
									}
								});
							}
						}
					}
					fzyid = "";
					total = 0;
					detail = "";
				}
				
			},
			error : function(){
				$.messager.alert('提示','获取归档总数失败，请联系管理员！','info');
			}
	
		}); 
	}
});

//浏览归档详情
function preview(index){
	var rows = $('#archivingListGrid').datagrid("getRows")[index];
	var detail = rows.detail;
	var arr = [];
	arr = detail.split(",");
	var items = "";
	for (var i = 0; i < arr.length; i++) {
		items += "<li>"+(i+1)+"."+arr[i]+"</li>"		
	}
	$('#details'+index).tooltip({
			position : 'right',
			content : "<div style='width:200px;height:auto;'> <h4>归档明细</h4> <div style='margin: 2px 0px;'><ul class='description' style='list-style-type:none;'>"+items+"</ul> </div> </div>",
			onShow : function() {
				$(this).tooltip('tip').css({
					borderColor : '#666'
				});
				
			}
		}); 
}

//归档操作
function archiving(index) {
	var rows = $("#archivingListGrid").datagrid("getRows")[index];
	var url=ctx+'/MedicalShootManage/EMRFileBrowse?tag=1&dialog=archivingDialog&fprn='+rows.fprn + '&fzyid=' +rows.fzyid 
	+ '&ftimes='+rows.ftimes+ '&fname='+encodeURI(encodeURI(rows.fname))+ '&fcydate='+new Date(rows.fcydate).format("yyyy-MM-dd")
	+ '&fbarcode='+rows.fbarcode;
	addTab("病案集中归档浏览", url,"", false);
	//if(rows.fstatus != null && rows.fstatus != '0'){
		/* $("#archivingDialog").dialog({
			maximizable : true,
			closed : false,
			modal : true,
			href: ctx+'/MedicalShootManage/EMRFileBrowse?tag=1&dialog=archivingDialog&fprn='+rows.fprn + '&fzyid=' +rows.fzyid 
				+ '&ftimes='+rows.ftimes+ '&fname='+encodeURI(encodeURI(rows.fname))+ '&fcydate='+new Date(rows.fcydate).format("yyyy-MM-dd")
				+ '&fbarcode='+rows.fbarcode,
			title : ''// "拍摄"
		}); */
		
	//}else{
	//	$.messager.alert('提示','该病历没有PDF文件，不能进行归档操作！','info');
	//}

}



</script>
</body>
</html>